package com.ruoyi.wms.controller;

import java.util.List;
import java.io.IOException;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.wms.domain.WmsBorrow;
import com.ruoyi.wms.service.IWmsBorrowService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 物料借用Controller
 * 
 * @author Yunzhh
 * @date 2021-11-05
 */
@RestController
@RequestMapping("/borrow")
public class WmsBorrowController extends BaseController
{
    @Resource
    private IWmsBorrowService wmsBorrowService;

//    @Autowired
//    private ICrmOrdersService iCrmOrdersService;

    /**
     * 查询物料借用列表
     */
    @PreAuthorize(hasPermi = "wms:borrow:list")
    @GetMapping("/list")
    public TableDataInfo list(WmsBorrow wmsBorrow)
    {
//        CrmOrders co = new CrmOrders();
//        List<CrmOrders> lst = iCrmOrdersService.selectCrmOrdersList(co);

//        String[] myArray = new String[0];
//        myArray[0] = "123";
//        wmsBorrowService.delCrmOrder(myArray);


        startPage();
        List<WmsBorrow> list = wmsBorrowService.selectWmsBorrowList(wmsBorrow);
        return getDataTable(list);
    }

    /**
     * 导出物料借用列表
     */
    @PreAuthorize(hasPermi = "wms:borrow:export")
    @Log(title = "物料借用", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WmsBorrow wmsBorrow) throws IOException
    {
        List<WmsBorrow> list = wmsBorrowService.selectWmsBorrowList(wmsBorrow);
        ExcelUtil<WmsBorrow> util = new ExcelUtil<WmsBorrow>(WmsBorrow.class);
        util.exportExcel(response, list, "物料借用数据");
    }

    /**
     * 获取物料借用详细信息
     */
    @PreAuthorize(hasPermi = "wms:borrow:query")
    @GetMapping(value = "/{borrowUuid}")
    public AjaxResult getInfo(@PathVariable("borrowUuid") String borrowUuid)
    {
        return AjaxResult.success(wmsBorrowService.selectWmsBorrowByBorrowUuid(borrowUuid));
    }

    /**
     * 新增物料借用
     */
    @PreAuthorize(hasPermi = "wms:borrow:add")
    @Log(title = "物料借用", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WmsBorrow wmsBorrow)
    {
        return toAjax(wmsBorrowService.insertWmsBorrow(wmsBorrow));
    }

    /**
     * 修改物料借用
     */
    @PreAuthorize(hasPermi = "wms:borrow:edit")
    @Log(title = "物料借用", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WmsBorrow wmsBorrow)
    {
        return toAjax(wmsBorrowService.updateWmsBorrow(wmsBorrow));
    }

    /**
     * 删除物料借用
     */
    @PreAuthorize(hasPermi = "wms:borrow:remove")
    @Log(title = "物料借用", businessType = BusinessType.DELETE)
	@DeleteMapping("/{borrowUuids}")
    public AjaxResult remove(@PathVariable String[] borrowUuids)
    {
        return toAjax(wmsBorrowService.deleteWmsBorrowByBorrowUuids(borrowUuids));
    }
}
